//
//  BackupsSwitchView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/1/27.
//

import SwiftUI

//自定义ai图文教程
struct AiCustomTutorialDialog: View {
    let onDismiss: (AiTutorialChildBean?) -> Void
    @State private var first : AiTutorialChildBean? = nil
    @State private var second : AiTutorialChildBean? = nil
    @State private var third : AiTutorialChildBean? = nil

    var body: some View {
        PopupBottomView(title: "教程") {
            VStack(spacing: 15) {
                HStack() {
                    VStack(alignment: .leading) {
                        Text(first?.title ?? "")
                            .font(.system(size: 16))
                            .foregroundStyle(.bgNormalText2)
                        Text(first?.subtitle ?? "")
                            .font(.system(size: 12))
                            .foregroundStyle(.bgNormalText4)
                    }
                    Spacer()
                }.padding(.horizontal,15)
                    .frame(height: 80)
                    .background(.bgItemGray)
                    .cornerRadius(15)
                    .contentShape(Rectangle())
                    .onTapGesture {
                        onDismiss(first)
                    }
                HStack() {
                    VStack(alignment: .leading) {
                        Text(second?.title ?? "")
                            .font(.system(size: 16))
                            .foregroundStyle(.bgNormalText2)
                        Text(second?.subtitle ?? "")
                            .font(.system(size: 12))
                            .foregroundStyle(.bgNormalText4)
                    }
                    Spacer()
                }.padding(.horizontal,15)
                    .frame(height: 80)
                    .background(.bgItemGray)
                    .cornerRadius(15)
                    .contentShape(Rectangle())
                    .onTapGesture {
                        onDismiss(second)
                    }
                HStack() {
                    VStack(alignment: .leading) {
                        Text(third?.title ?? "")
                            .font(.system(size: 16))
                            .foregroundStyle(.bgNormalText2)
                        Text(third?.subtitle ?? "")
                            .font(.system(size: 12))
                            .foregroundStyle(.bgNormalText4)
                    }
                    Spacer()
                }.padding(.horizontal,15)
                    .frame(height: 80)
                    .background(.bgItemGray)
                    .cornerRadius(15)
                    .contentShape(Rectangle())
                    .onTapGesture {
                        onDismiss(third)

                    }
            }.padding(.top,15)
        }.onAppear{
            first = configManager.getConfig().aiTutorial?.first ?? AiTutorialChildBean()
            second = configManager.getConfig().aiTutorial?.second ?? AiTutorialChildBean()
            third = configManager.getConfig().aiTutorial?.third ?? AiTutorialChildBean()
        }
    }
}

//#Preview {
//    AiCustomTutorialDialog()
//}
//定义预览提供者
struct AiCustomTutorialDialog_Previews: PreviewProvider {
    static var previews: some View {
        //使用预览共享配置
        configurePreviewEnvironment(for: AiCustomTutorialDialog(){_ in})
    }
}
